﻿#region Usings

using System.Data.Entity.ModelConfiguration;
using Rail.Net.Core.Model;

#endregion

namespace Rail.Net.Data.Configuration
{
    public class TravelerMap : EntityTypeConfiguration<Traveler>
    {
        public TravelerMap()
        {
            ToTable("Travelers");
            HasKey(traveler => traveler.Id);

            Property(traveler => traveler.AgeFrom).HasPrecision(18, 2).IsOptional();
            Property(traveler => traveler.AgeTo).HasPrecision(18, 2).IsOptional();
            Property(traveler => traveler.PriceShare).HasPrecision(18, 6).IsRequired();

            HasRequired(traveler => traveler.TravelerCombination).WithMany(travelerCombination => travelerCombination.Travelers);
            HasOptional(traveler => traveler.DiscountOptions).WithMany(discountOption => discountOption.Travelers).Map( m => m.MapKey("DiscountOption_Id"));
        }
    }
}